package com.ruoyi.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.NumberConfig;
import com.ruoyi.business.service.INumberConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 编号配置Controller
 *
 * @author yangmeng
 * @date 2023-07-23
 */
@RestController
@RequestMapping("/business/config")
public class NumberConfigController extends BaseController {
    @Autowired
    private INumberConfigService numberConfigService;

    /**
     * 查询编号配置列表
     */
    @PreAuthorize("@ss.hasPermi('business:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(NumberConfig numberConfig) {
        startPage();
        List<NumberConfig> list = numberConfigService.selectNumberConfigList(numberConfig);
        return getDataTable(list);
    }

    /**
     * 导出编号配置列表
     */
    @PreAuthorize("@ss.hasPermi('business:config:export')")
    @Log(title = "编号配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NumberConfig numberConfig) {
        List<NumberConfig> list = numberConfigService.selectNumberConfigList(numberConfig);
        ExcelUtil<NumberConfig> util = new ExcelUtil<NumberConfig>(NumberConfig.class);
        util.exportExcel(response, list, "编号配置数据");
    }

    /**
     * 获取编号配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:config:query')")
    @GetMapping(value = "/{configId}")
    public AjaxResult getInfo(@PathVariable("configId") Long configId) {
        return success(numberConfigService.selectNumberConfigByConfigId(configId));
    }

    /**
     * 新增编号配置
     */
    @PreAuthorize("@ss.hasPermi('business:config:add')")
    @Log(title = "编号配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NumberConfig numberConfig) {
        return toAjax(numberConfigService.insertNumberConfig(numberConfig));
    }

    /**
     * 修改编号配置
     */
    @PreAuthorize("@ss.hasPermi('business:config:edit')")
    @Log(title = "编号配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody NumberConfig numberConfig) {
        return toAjax(numberConfigService.updateNumberConfig(numberConfig));
    }

    /**
     * 删除编号配置
     */
    @PreAuthorize("@ss.hasPermi('business:config:remove')")
    @Log(title = "编号配置", businessType = BusinessType.DELETE)
    @PostMapping("/delete/{configIds}")
    public AjaxResult remove(@PathVariable Long[] configIds) {
        return toAjax(numberConfigService.deleteNumberConfigByConfigIds(configIds));
    }
}
